package net.qhzw.vip.qiyu.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import net.qhzw.vip.qiyu.entity.DtsCarRental;
import net.qhzw.vip.qiyu.model.WarningQuery;
import net.qhzw.vip.qiyu.result.JsonResult;
import net.qhzw.vip.qiyu.service.DtsCarRentalService;
import net.qhzw.vip.qiyu.service.SysUserService;
import net.qhzw.vip.qiyu.util.MyDateUtils;
import net.qhzw.vip.qiyu.util.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

@RestController
@RequestMapping("sys/warning")
@Api(tags = "担保站点风险预警")
@Slf4j
public class SysWarningController {

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private DtsCarRentalService dtsCarRentalService;

    @ApiOperation(value = "分页查询担保站点风险预警")
    @GetMapping
    public JsonResult findByPage(WarningQuery query) {
        Long shopId = SecurityUtils.getLoginUser().getShopId();
        Map<String, Object> result = sysUserService.getWarningByPage(shopId, query);
        return JsonResult.ok(result);
    }

    @ApiOperation(value = "分页查询骑遇风险预警")
    @GetMapping("QY")
    public JsonResult findByPageQY(WarningQuery query) {
        Long shopId = SecurityUtils.getLoginUser().getShopId();
        Map<String, Object> result = sysUserService.findByPageQY(query, shopId);
        return JsonResult.ok(result);
    }


    @ApiOperation(value = "修改担保状态")
    @PostMapping("audit")
    public JsonResult audit(@RequestBody Map<String, String> param) {
        Long carRentalId = Long.valueOf(param.get("carRentalId"));
        Byte warrantyStatus = Byte.valueOf(param.get("warrantyStatus"));
        DtsCarRental dtsCarRental = new DtsCarRental();
        dtsCarRental.setId(carRentalId);
        dtsCarRental.setWarrantyStatus(warrantyStatus);
        boolean update = dtsCarRentalService.updateById(dtsCarRental);
        if (update) {
            return JsonResult.ok();
        }
        return JsonResult.fail();
    }



}
